#include <iostream>
#include <stack>
#include <unordered_map>
using namespace std;

bool isValidSequence(string sequence) {
    stack<char> st;
    unordered_map<char, char> closingToOpening = {
        {')', '('},
        {']', '['},
        {'}', '{'},
        {'>', '<'}
    };

    for (char bracket : sequence) {
        if (bracket == '(' || bracket == '[' || bracket == '{' || bracket == '<') {
            st.push(bracket);
        } else if (bracket == ')' || bracket == ']' || bracket == '}' || bracket == '>') {
            if (st.empty() || st.top() != closingToOpening[bracket]) {
                return false;
            }
            st.pop();
        }
    }

    return st.empty();
}

int main() {
    string sequence;
    cout << "Введите скобочную последовательность: ";
    cin >> sequence;
    
    bool isValid = isValidSequence(sequence);
    cout << (isValid ? "true" : "false") << endl;

    return 0;
}

